class Solution:
    def topKFrequent(self, nums: list[int], k: int) -> list[int]:
        return [i for i, j in sorted(list(Counter(nums).items()), key=lambda c: c[1], reverse=True)][:k]